<?php
	include "../ini.php";
	include "../../libraries/xl_san_pham.php";
	include "../../libraries/xl_loai_san_pham.php";
	$dt_xl_san_pham =  new xl_san_pham;
	$dt_xl_loai_san_pham =  new xl_loai_san_pham;
	
	if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
		$_SESSION['msg'] = "Lỗi! Dữ liệu  không hợp lệ, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;		
	}
	
	$ma =$_GET['id'];	
	$san_pham = $dt_xl_san_pham->xem($ma);
	if($san_pham == NULL){
		$_SESSION['msg'] = "Lỗi! Dữ liệu không tồn tại, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	
	function in_ten_loai_cha($ds_loai_san_pham,$ma, $kitu, $machon){// dùng trong option
		foreach($ds_loai_san_pham as $loai_san_pham){
			if($loai_san_pham['ma_loai_cha'] == $ma){
				if($loai_san_pham['ma'] == $machon){
					echo '<option selected="selected" value="'.$loai_san_pham['ma'].'">'.$kitu.$loai_san_pham['ten'].'</option>';
				}else{
					echo '<option value="'.$loai_san_pham['ma'].'">'.$kitu.$loai_san_pham['ten'].'</option>';
				}
				
				in_ten_loai_cha($ds_loai_san_pham,$loai_san_pham['ma'],$kitu.$kitu,$machon);
			}
		}
	}
	
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include"../includes/js_css.php"?>
</head>
<body>
<div id="body-wrapper"> <!-- Wrapper for the radial gradient background -->
  
  <?php include"../widgets/sidebar.php"?>
  <!-- End #sidebar -->
  
  <div id="main-content"> <!-- Main Content Section with everything -->
    
    <?php include"../widgets/noscript.php"?>
    <div class="clear"></div>
    <!-- End .clear -->
    
    <div class="content-box"><!-- Start Content Box -->
      
      <div class="content-box-header">
        <h3>Cập nhật sản phẩm</h3>
        <div class="clear"></div>
      </div>
      <!-- End .content-box-header -->
      
      <div class="content-box-content"> 
        
        <!-- End #tab1 -->
        
        <div class="tab-content default-tab" id="tab2">
          <form action="edit_sm.php" method="post"  enctype="multipart/form-data" name="f2">
          <input type="hidden" name="ma" value="<?php echo $san_pham['ma']?>" />
            <fieldset>
              <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
              <table width="100%">
                <tbody>
                  <div>
                  <?php message()?>
                </div>
                  <tr class="alt-row">
                    <td >Tên sản phẩm</td>
                    <td ><input class="text-input medium-input datepicker" type="text" id="ten" name="ten" value="<?php echo $san_pham['ten']?>"/></td>
                  </tr>
                  <tr>
                    <td>Loại sản phẩm</td>
                    <td><select name="ma_loai" >
                  <?php 
						  $ds_loai_san_pham = $dt_xl_loai_san_pham->danh_sach_all();
						  in_ten_loai_cha($ds_loai_san_pham,0,'==',$san_pham['ma_loai']);
				  ?>
                </select>
                    </td>
                  </tr>
                  
                  <tr class="alt-row">
                    <td>Đơn giá</td>
                    <td> <input class="text-input medium-input datepicker" type="text" id="don_gia" name="don_gia" value="<?php echo $san_pham['don_gia']?>"/>VND</td>
                  </tr>                  
                  <tr>
                    <td>Hình ảnh</td>
                    <td>	<input class="text-input small-input" type="file" id="hinh" name="hinh" /><br>*.gif , *.jpg ,*.png &lt; 2000kb)<br /><br />
                            <img src="../../uploads/san_pham/<?php echo $san_pham['hinh']?>" width="80px" height="80px"/>
                      </td>
                  </tr>
                 <tr class="alt-row">
                    <td>Hiển thị sản phẩm mới</td>
                    <td><input type="radio" name="san_pham_moi" value="1" <?php if($san_pham['san_pham_moi']==1) echo (" checked='checked'")?>  /> Hiện thị<br />
						<input type="radio" name="san_pham_moi" value="0"<?php if($san_pham['san_pham_moi']==0) echo (" checked='checked'")?>/> Không hiện thị</td>  
                  </tr> 
                  <tr>
                    <td>Trạng thái</td>
                    <td><input type="radio" name="trang_thai"  <?php if($san_pham['trang_thai']==1) echo (" checked='checked'")?> value="1"/>Còn hàng<br />
						<input type="radio" name="trang_thai"  <?php if($san_pham['trang_thai']==0) echo (" checked='checked'")?> value="0"/> Không còn hàng</td>                    
                  </tr>
                  <tr class="alt-row">
                    <td>Ngày Đăng</td>
                    <td><script>
						$(function() {
							$( "#ngay_tao" ).datepicker({
								showOn: "button",
								buttonImage: "../images/calendar.gif",
								buttonImageOnly: true
							});
						});
					</script>
					<div class="demo">
<input type="text"  class="text-input small-input" id="ngay_tao" name="ngay_tao" value="<?php echo $san_pham['ngay_tao']?>">

</div><!-- End demo -->
                    </td>
                  </tr>
                  <tr >
                    <td>Mô tả tóm tắt</td>
                    <td>
                    	<textarea class="text-input textarea " id="mo_ta_tom_tat" name="mo_ta_tom_tat" cols="79" rows="10"><?php echo $san_pham['mo_ta_tom_tat']?></textarea>
                    <script type="text/javascript">
					CKEDITOR.replace( 'mo_ta_tom_tat',{
						sink :'kama',
						toolbar :[	
							['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
							['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
							['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
							['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
							['Link','Unlink','Anchor'],
							['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
							'/',
							['Styles','Format','Font','FontSize'],
							['TextColor','BGColor']]});

			//]]>
			</script>
                    </td>
                  </tr>
                  <tr class="alt-row">
                    <td>Mô tả chi tiết</td>
                    <td>
                    	<textarea class="text-input textarea " id="mo_ta_chi_tiet" name="mo_ta_chi_tiet" cols="20" rows="5"><?php echo $san_pham['mo_ta_chi_tiet']?></textarea>
                    <script type="text/javascript">
					CKEDITOR.replace( 'mo_ta_chi_tiet',{
						sink :'kama',
						toolbar :[	
							['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
							['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
							['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
							['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
							['Link','Unlink','Anchor'],
							['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
							'/',
							['Styles','Format','Font','FontSize'],
							['TextColor','BGColor']]});
			//]]>
			</script>
                    </td>
                  </tr>
                  <tr>
                    <td style="text-align:center !important" colspan="2"><input class="button" type="submit" value="Cập nhật" name="cap_nhat">
                      
                      <input class="button" type="button" value="Thoát" onclick="window.location.href='list.php'"></td>
                  </tr>
                </tbody>
              </table>
              
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
            
          </form>
        </div>
        <!-- End #tab2 --> 
        
      </div>
      <!-- End .content-box-content --> 
      
    </div>
    <!-- End .content-box -->
    
    <div class="clear"></div>
    <?php include"../widgets/footer.php"?>
  </div>
  <!-- End #main-content --> 
  
</div>
</body>
</html>
